﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace saktGen
{
	class Program
	{
		static void Main(string[] args)
		{
			Gen_sakt();

			Console.WriteLine("ok！");

			Console.ReadLine();
		}

		private static string[] nsmap =
		{
			"NAMESPACE_INDEX_00_",
			"NAMESPACE_INDEX_01_Windows_Media_Capture",
			"NAMESPACE_INDEX_02_Windows_Media_Protection",
			"NAMESPACE_INDEX_03_Windows_Media_PlayTo",
			"NAMESPACE_INDEX_04_Windows_System",
			"NAMESPACE_INDEX_05_Windows_Devices_Input",
			"NAMESPACE_INDEX_06_Windows_Storage_Streams",
			"NAMESPACE_INDEX_07_Windows_UI",
			"NAMESPACE_INDEX_08_Windows_UI_Input",
			"NAMESPACE_INDEX_09_Windows_UI_Core",
			"NAMESPACE_INDEX_0a_Windows_UI_Text",
			"NAMESPACE_INDEX_0b_Windows_Foundation",
			"NAMESPACE_INDEX_0c_Windows_Foundation_Collections",
			"NAMESPACE_INDEX_0d_Windows_ApplicationModel_DataTransfer",
			"NAMESPACE_INDEX_0e_Windows_UI_Xaml_Resources",
			"NAMESPACE_INDEX_0f_Windows_Web",
			"NAMESPACE_INDEX_10_Windows_UI_Xaml",
			"NAMESPACE_INDEX_11_Windows_UI_Xaml_Media",
			"NAMESPACE_INDEX_12_Windows_UI_Xaml_Media_Animation",
			"NAMESPACE_INDEX_13_Windows_UI_Xaml_Input",
			"NAMESPACE_INDEX_14_Windows_UI_Xaml_Shapes",
			"NAMESPACE_INDEX_15_Windows_UI_Xaml_Documents",
			"NAMESPACE_INDEX_16_Windows_UI_Xaml_Controls",
			"NAMESPACE_INDEX_17_Windows_UI_Xaml_Collections",
			"NAMESPACE_INDEX_18_Windows_UI_Xaml_Internal",
			"NAMESPACE_INDEX_19_Windows_UI_Xaml_Media_Imaging",
			"NAMESPACE_INDEX_1a_",
			"NAMESPACE_INDEX_1b_Windows_UI_Xaml_Controls_Primitives",
			"NAMESPACE_INDEX_1c_Windows_UI_Xaml_Automation",
			"NAMESPACE_INDEX_1d_Windows_UI_Xaml_Automation_Peers",
			"NAMESPACE_INDEX_1e_Windows_UI_Xaml_Automation_Provider",
			"NAMESPACE_INDEX_1f_Windows_UI_Xaml_Data",
			"NAMESPACE_INDEX_20_Windows_UI_Xaml_Media_Media3D",
			"NAMESPACE_INDEX_21_Windows_UI_Xaml_Markup",
			"NAMESPACE_INDEX_22_Windows_Graphics_Printing",
			"NAMESPACE_INDEX_23_Windows_UI_Xaml_Printing",
			"NAMESPACE_INDEX_24_MS_Internal_Automation",
			"NAMESPACE_INDEX_25_Windows_UI_Xaml_Navigation",
			"NAMESPACE_INDEX_26_WindowsUI_Xaml_Interop",
		};


		static void Gen_sakp()
		{
			
		}

		

		static void Gen_sakt()
		{


			List<string> type_indexs_names = new List<string>();
			string[] lines = File.ReadAllLines("sakt_0__dynamic_initializer_for__sakt__.asm");

			var itemcount = lines.Length / 11;

			StringBuilder sb = new StringBuilder();


			for (int i = 0; i < itemcount; i++)
			{
				string m_nKnown = lines[11 * i + 0];

				string m_pwsz = lines[11 * i + 3];

				{
					m_nKnown = m_nKnown.Split(',')[1].Replace("h", "").Trim();
					m_nKnown = m_nKnown.PadLeft(8, '0');
					m_nKnown = "0x" + m_nKnown;
				}

				{
					m_pwsz = m_pwsz.Split('"')[1].Replace(".", "").Replace("!", "").Replace("?", "").Trim();
				}



				var iiii = Convert.ToUInt32(m_nKnown, 16);
				var typeindexname = string.Format("TYPE_INDEX_{0:X8}_{1}",iiii, m_pwsz);
				type_indexs_names.Add(typeindexname);




				Console.WriteLine("#define {0} {1}U", typeindexname.PadRight(60), m_nKnown);

				sb.AppendFormat("#define {0} {1}U\r\n", typeindexname.PadRight(60), m_nKnown);
			}


			sb.AppendLine();
			sb.AppendLine();
			sb.AppendLine();
			sb.AppendLine();
			sb.AppendLine();

			

			for (int i = 0; i < itemcount; i++)
			{
				string m_nKnown = lines[11 * i + 0];
				string m_nBase = lines[11 * i + 1];
				string m_cwc = lines[11 * i + 2];
				string m_pwsz = lines[11 * i + 3];
				string m_pfn = lines[11 * i + 4];
				string m_nNamespace = lines[11 * i + 5];
				string m_flags = lines[11 * i + 6];
				string m_flags4 = lines[11 * i + 7];
				string m_typeHandle = lines[11 * i + 8];
				string m_nInheritanceDepth = lines[11 * i + 9];
				string m_pClassInfo = lines[11 * i + 10];


				{
					m_nKnown = m_nKnown.Split(',')[1].Replace("h", "").Trim();
					m_nKnown = m_nKnown.PadLeft(8, '0');
					m_nKnown = "0x" + m_nKnown;
				}


				{
					m_nBase = m_nBase.Split(',')[1].Replace("h", "").Trim();
					m_nBase = m_nBase.PadLeft(8, '0');
					m_nBase = "0x" + m_nBase;
				}


				{
					m_pwsz = m_pwsz.Split('"')[1];
				}
				

				{
					var aaa = m_pfn.IndexOf("offset ");
					if (aaa != -1)
					{
						var bbb = m_pfn.IndexOf("(");

						m_pfn = m_pfn.Substring(aaa, bbb - aaa).Replace("offset ", "");
					}
					else
					{
						m_pfn = "NULL";
					}
				}

				{
					m_nNamespace = m_nNamespace.Split(',')[1].Replace("h", "").Trim();
					m_nNamespace = m_nNamespace.PadLeft(8, '0');
					m_nNamespace = "0x" + m_nNamespace;
				}


				{
					m_flags = m_flags.Split(',')[1].Replace("h", "").Trim();
					m_flags = m_flags.PadLeft(8, '0');
					//m_flags = "0x" + m_flags;
				}

				{
					m_flags4 = m_flags4.Split(',')[1].Replace("h", "").Trim();
					m_flags4 = m_flags4.PadLeft(8, '0');
					m_flags4 = "0x" + m_flags4;

					m_flags = m_flags4 + m_flags;
				}


				{
					m_typeHandle = m_typeHandle.Split(',')[1].Replace("h", "").Trim();
					m_typeHandle = m_typeHandle.PadLeft(8, '0');
					m_typeHandle = m_typeHandle.Substring(m_typeHandle.Length - 8, 8);
					m_typeHandle = "0x" + m_typeHandle;
				}

				{
					m_nInheritanceDepth = m_nInheritanceDepth.Split(',')[1].Replace("h", "").Trim();
					m_nInheritanceDepth = m_nInheritanceDepth.PadLeft(8, '0');
					m_nInheritanceDepth = m_nInheritanceDepth.Substring(m_nInheritanceDepth.Length - 8, 8);
					m_nInheritanceDepth = "0x" + m_nInheritanceDepth;
				}




				string f = @"	*
		{0},
		{1},
		LEN_STR_PAIR(L""{2}""),
		NULL,//&{3},
		{4},
		{5},
		{6},
		{7},
		NULL
	#,";


				var iiii = Convert.ToInt32(m_nBase, 16);

				var nsindex = Convert.ToInt32(m_nNamespace, 16);

				string s = string.Format(f, type_indexs_names[i], type_indexs_names[iiii], m_pwsz, m_pfn, nsmap[nsindex], m_flags, m_typeHandle,
					m_nInheritanceDepth);

				sb.AppendLine(s.Replace('*', '{').Replace('#', '}'));
				Console.WriteLine(s.Replace('*', '{').Replace('#', '}'));

			}




			File.WriteAllText("sakt.h", sb.ToString());
		}
	}
}
